Collection

interface Collection<out E> : Iterable<E>

A generic collection of elements. Methods in this interface support only read-only access to the collection; read/write access is supported through the MutableCollection interface.

Parameters

E

the type of elements contained in the collection. The collection is covariant in its element type.

Functions

contains
Link copied to clipboard
abstract operator fun contains(element: @UnsafeVariance E): Boolean

Checks if the specified element is contained in this collection.

containsAll
Link copied to clipboard
abstract fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean

Checks if all elements in the specified collection are contained in this collection.

isEmpty
Link copied to clipboard
abstract fun isEmpty(): Boolean

Returns true if the collection is empty (contains no elements), false otherwise.

iterator
Link copied to clipboard
abstract operator override fun iterator(): Iterator<E>

Properties

size
Link copied to clipboard
abstract val size: Int

Returns the size of the collection.

Inheritors

AbstractCollection
Link copied to clipboard
MutableCollection
Link copied to clipboard
List
Link copied to clipboard
Set
Link copied to clipboard
MatchGroupCollection
Link copied to clipboard
UByteArray
Link copied to clipboard
UIntArray
Link copied to clipboard
ULongArray
Link copied to clipboard
UShortArray
Link copied to clipboard

Extensions

containsAll
Link copied to clipboard
inline fun <T> Collection<T>.containsAll(elements: Collection<T>): Boolean

Checks if all elements in the specified collection are contained in this collection.

count
Link copied to clipboard
inline fun <T> Collection<T>.count(): Int

Returns the number of elements in this collection.

indices
Link copied to clipboard
val Collection<*>.indices: IntRange

Returns an IntRange of the valid indices for this collection.

isNotEmpty
Link copied to clipboard
inline fun <T> Collection<T>.isNotEmpty(): Boolean

Returns true if the collection is not empty.

isNullOrEmpty
Link copied to clipboard
inline fun <T> Collection<T>?.isNullOrEmpty(): Boolean

Returns true if this nullable collection is either null or empty.

orEmpty
Link copied to clipboard
inline fun <T> Collection<T>?.orEmpty(): Collection<T>

Returns this Collection if it's not null and the empty list otherwise.

plus
Link copied to clipboard
operator fun <T> Collection<T>.plus(element: T): List<T>

Returns a list containing all elements of the original collection and then the given element.

operator fun <T> Collection<T>.plus(elements: Array<out T>): List<T>

Returns a list containing all elements of the original collection and then all elements of the given elements array.

operator fun <T> Collection<T>.plus(elements: Iterable<T>): List<T>

Returns a list containing all elements of the original collection and then all elements of the given elements collection.

operator fun <T> Collection<T>.plus(elements: Sequence<T>): List<T>

Returns a list containing all elements of the original collection and then all elements of the given elements sequence.

plusElement
Link copied to clipboard
inline fun <T> Collection<T>.plusElement(element: T): List<T>

Returns a list containing all elements of the original collection and then the given element.

random
Link copied to clipboard
inline fun <T> Collection<T>.random(): T

Returns a random element from this collection.

fun <T> Collection<T>.random(random: Random): T

Returns a random element from this collection using the specified source of randomness.

randomOrNull
Link copied to clipboard
inline fun <T> Collection<T>.randomOrNull(): T?

Returns a random element from this collection, or null if this collection is empty.

fun <T> Collection<T>.randomOrNull(random: Random): T?

Returns a random element from this collection using the specified source of randomness, or null if this collection is empty.

toBooleanArray
Link copied to clipboard
fun Collection<Boolean>.toBooleanArray(): BooleanArray

Returns an array of Boolean containing all of the elements of this collection.

toByteArray
Link copied to clipboard
fun Collection<Byte>.toByteArray(): ByteArray

Returns an array of Byte containing all of the elements of this collection.

toCharArray
Link copied to clipboard
fun Collection<Char>.toCharArray(): CharArray

Returns an array of Char containing all of the elements of this collection.

toDoubleArray
Link copied to clipboard
fun Collection<Double>.toDoubleArray(): DoubleArray

Returns an array of Double containing all of the elements of this collection.

toFloatArray
Link copied to clipboard
fun Collection<Float>.toFloatArray(): FloatArray

Returns an array of Float containing all of the elements of this collection.

toIntArray
Link copied to clipboard
fun Collection<Int>.toIntArray(): IntArray

Returns an array of Int containing all of the elements of this collection.

toLongArray
Link copied to clipboard
fun Collection<Long>.toLongArray(): LongArray

Returns an array of Long containing all of the elements of this collection.

toMutableList
Link copied to clipboard
fun <T> Collection<T>.toMutableList(): MutableList<T>

Returns a new MutableList filled with all elements of this collection.

toShortArray
Link copied to clipboard
fun Collection<Short>.toShortArray(): ShortArray

Returns an array of Short containing all of the elements of this collection.

toTypedArray
Link copied to clipboard
expect inline fun <T> Collection<T>.toTypedArray(): Array<T>
actual inline fun <T> Collection<T>.toTypedArray(): Array<T>

Returns a typed array containing all of the elements of this collection.

actual inline fun <T> Collection<T>.toTypedArray(): Array<T>
actual inline fun <T> Collection<T>.toTypedArray(): Array<T>

Returns a typed array containing all of the elements of this collection.

toUByteArray
Link copied to clipboard

Returns an array of UByte containing all of the elements of this collection.

toUIntArray
Link copied to clipboard

Returns an array of UInt containing all of the elements of this collection.

toULongArray
Link copied to clipboard

Returns an array of ULong containing all of the elements of this collection.

toUShortArray
Link copied to clipboard

Returns an array of UShort containing all of the elements of this collection.

waitForMultipleFutures
Link copied to clipboard
fun <T> Collection<Future<T>>.waitForMultipleFutures(millis: Int): Set<Future<T>>